#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i, a, b) for (int i = a; i <= b; i++)
#define R(i, a, b) for (int i = a; i >= b; i--)

#define mk(a, b) make_pair(a, b)
#define inv(x) ksm(x, Mod - 2)
#define mem(a, b) memset(a, b, sizeof a)

#define De(x) cerr << "------------------" << x << "--------------" << endl
#define Debug() cerr << "----------------------------------------" << endl
#define lson(x) x << 1
#define rson(x) x << 1 | 1

const int N = 2e5 + 5, TN = 1e6 + 5, Mod = 998244353, inf = INT_MAX, Inf = LONG_LONG_MAX;
inline int ksm(int a, int b);
inline int read();
string s;
int T = 1, ans = 0, n, m, k, a[N], x, l, r, top, lmax[2][N], rmax[2][N], nb;

int Ans[2][N];

int o1[N], o2[N], o3[N];

struct node {
	int x, y; // val wz
} stk[N];

inline void dfs(int l, int r, int val, int kk) {
	if (kk > nb) return;
	if (l == 1 && r == n) {
		nb = min(nb, kk);
		return;
	}
	int min_to = min(a[l - 1], a[r + 1]);
	if (min_to == a[l - 1]) dfs(lmax[0][l - 1], rmax[0][l - 1], min_to, kk + k);
	if (min_to == a[r + 1]) dfs(lmax[0][r + 1], rmax[0][r + 1], min_to, kk + k);
}
inline void dfs1(int l, int r, int val, int kk, int kkk) {
	if (kk > nb) return ;
	if (l == 1 && r == n) {
		nb = min(nb, kk);
		return;
	}
	int min_to = min(a[l - 1], a[r + 1]);
	if (min_to == a[l - 1] && min_to != a[r + 1]) dfs1(lmax[kkk][l - 1], rmax[kkk][l - 1], min_to, kk + k, kkk);
	if (min_to == a[r + 1] && min_to != a[l - 1]) dfs1(lmax[kkk][r + 1], rmax[kkk][r + 1], min_to, kk + k, kkk);
	if (min_to == a[r + 1] && min_to == a[l - 1]) dfs1(lmax[kkk][r + 1], rmax[kkk][r + 1], min_to, kk + k, kkk);
}

inline void Solve() {
	top = 0;
	F(i, 1, n) {
		while (top && stk[top].x < a[i]) {
			rmax[0][stk[top--].y] = i - 1;
		}
		stk[++top] = (node) {
			a[i], i
		};
	}
	F(i, 1, top) {
		rmax[0][stk[i].y] = n;
	}
	top = 0;
	R(i, n, 1) {
		while (top && stk[top].x < a[i]) {
			lmax[0][stk[top--].y] = i + 1;
		}
		stk[++top] = (node) {
			a[i], i
		};
	}
	F(i, 1, top) {
		lmax[0][stk[i].y] = 1;
	}
}

inline void Solve1() {
	top = 0;
	F(i, 1, n) {
		while (top && stk[top].x < a[i]) {
			rmax[1][stk[top--].y] = i - 1;
		}
		stk[++top] = (node) {
			a[i], i
		};
	}
	F(i, 1, top) {
		rmax[1][stk[i].y] = n;
	}
	top = 0;
	R(i, n, 1) {
		while (top && stk[top].x < a[i]) {
			lmax[1][stk[top--].y] = i + 1;
		}
		stk[++top] = (node) {
			a[i], i
		};
	}
	F(i, 1, top) {
		lmax[1][stk[i].y] = 1;
	}
}

signed main() {
	 freopen("summer.in", "r", stdin);
	freopen("summer.out", "w", stdout);
	n = read(), k = read();
	F(i, 1, n) a[i] = read();
	a[0] = Inf, a[n + 1] = Inf;
	T = read();
	int kdjk = 0;
	F(i, 1, T) o1[i] = read(), o2[i] = read(), o3[i] = read();
	F(i, 2, T) if (o1[i] == o1[i - 1]) kdjk++;
	if (kdjk == T - 1) {
		swap(a[o1[1]], a[o1[1] + 1]);
		Solve();
		swap(a[o1[1]], a[o1[1] + 1]);
		Solve1();
		F(kkkk, 1, T) {
			x = o1[kkkk], l = o2[kkkk], r = o3[kkkk];
			swap(a[x], a[x + 1]);
			ans = 0;
			//	Solve();
			F(i, l, r ) {
				nb = Inf;
				if (Ans[(kkkk - 1) % 2][i]) {
					ans += Ans[(kkkk - 1) % 2][i];
					continue;
				}
				dfs1(lmax[(kkkk - 1) % 2][i], rmax[(kkkk - 1) % 2][i], a[i], 0, (kkkk - 1) % 2);
				ans += nb + n - 1;
				Ans[(kkkk - 1) % 2][i] = nb + n - 1;
			}
			printf("%lld\n", ans);
		}
	} else {
		F(kkkk, 1, T) {
			x = o1[kkkk], l = o2[kkkk], r = o3[kkkk];
			swap(a[x], a[x + 1]);
			ans = 0;
			Solve();
			F(i, l, r ) {
				nb = Inf;
				dfs(lmax[0][i], rmax[0][i], a[i], 0);
				ans += nb + n - 1;
			}
			printf("%lld \n", ans);
		}
	}
	return 0;
}
inline int read() {
	int x = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')
			f *= -1;
		c = getchar();
	}
	while (c <= '9' && c >= '0') {
		x = (x << 3) + (x << 1) + (c ^ 48);
		c = getchar();
	}
	return x * f;
}
inline int ksm(int a, int b) {
	int aa = 1;
	while (b) {
		if (b & 1)
			aa *= a, aa %= Mod;
		a *= a;
		a %= Mod;
		b >>= 1;
	}
	return aa;
}
